// Block File Copy
// By Ben 11:56 20/09/2016
#include <iostream>
#include <Windows.h>

using namespace std;
using std::cout;
using std::endl;

bool MyFileCopy(string src, string dest, int chunksize = 1024){
	FILE *fin = NULL;
	FILE *fout = NULL;
	char *Buffer = NULL;
	size_t BytesRead = 0;

	//Open source file.
	fin = fopen(src.c_str(), "rb");

	if (!fin){
		return false;
	}

	fout = fopen(dest.c_str(), "wb");

	if (!fout){
		fclose(fin);
		return false;
	}

	//Resize Buffer
	Buffer = new char[chunksize];

	//Do file copy.
	while ((BytesRead = fread(Buffer, sizeof(char), chunksize, fin)) == chunksize){
		fwrite(Buffer, sizeof(char), chunksize, fout);
	}

	//Write left over
	fwrite(Buffer, sizeof(char), BytesRead, fout);

	//Tidy up time.
	fclose(fout);
	fclose(fin);

	delete[]Buffer;
	return true;
}

int main(int argc, char *argv[]){
	//Do file copy
	if (!MyFileCopy("C:\\ben\\comp.zip", "C:\\ben\\ben.zip", 2048)){
		cout << "File Copy Faild!" << endl;
		exit(1);
	}

	//File done message
	cout << "File Copy OK...." << endl;

	system("pause");
	return 0;
}